package com.itheima.d1_ip;

import java.net.InetAddress;

/**
 * 目标：掌握InetAddress类的使用。
 */
public class InetAddressTest {
    public static void main(String[] args) throws Exception {
        // 1、获取本机IP地址对象的
        InetAddress localHost = InetAddress.getLocalHost();
        System.out.println("localHost = " + localHost);

        // 2、获取指定IP或者域名的IP地址对象。
        InetAddress ip1 = InetAddress.getByName("127.0.0.1");
        System.out.println("ip1 = " + ip1);

        InetAddress ip2 = InetAddress.getByName("www.baidu.com");
        System.out.println("ip2 = " + ip2);

        System.out.println(ip2.getHostName());
        System.out.println(ip2.getHostAddress());


        // ping www.baidu.com
        boolean reachable = InetAddress.getByName("127.0.0.1").isReachable(2000);
        System.out.println("reachable = " + reachable);

        boolean reachable1 = ip2.isReachable(9000);
        System.out.println("reachable1 = " + reachable1);
    }
}
